package leetcode.offer;

/**
 * ClassName: Offer14I_CuttingRope
 * Description:
 * date: 2021-11-19 22:23
 *
 * @author liyifan
 */
public class Offer14I_CuttingRope {
    public int cuttingRope(int n) {
        if (n < 4)
            return n - 1;
        int[] dp = new int[n + 1];
        dp[1] = 1;
        dp[2] = 2;
        dp[3] = 3;
        for (int i = 4;i <= n;i++) {
            for (int j = 1;j <= i / 2;j++) {
                dp[i] = Math.max(dp[i], dp[j] * dp[i - j]);
            }
        }
        return dp[n];
    }

}
